// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';
// 申明请求对象
const workorderRequest = {
    // dict请求的基本url
    BASE_URL :  confing.PRO_URL + "/wororder",
    // 请求的API
    list(page = 1,limit = 10,proWorkorder,callback){
        // url
        let url = this.BASE_URL + "/list?page=" + page + "&limit=" + limit;
        if(proWorkorder){
            if(proWorkorder.workorderCode){
                url += "&workorderCode=" + proWorkorder.workorderCode;
            }
            if(proWorkorder.workorderName){
                url += "&workorderName=" + proWorkorder.workorderName;
            }
            if(proWorkorder.sourceCode){
                url += "&sourceCode=" + proWorkorder.sourceCode;
            }
            if(proWorkorder.productCode){
                url += "&productCode=" + proWorkorder.productCode;
            }
            if(proWorkorder.productName){
                url += "&productName=" + proWorkorder.productName;
            }
            if(proWorkorder.clientCode){
                url += "&clientCode=" + proWorkorder.clientCode;
            }

            if(proWorkorder.clientName){
                url += "&clientName=" + proWorkorder.clientName;
            }
        }
        // 发送请求
        request.get(url,callback);
    },
    //全部分页请求
    get(page = 1,limit = 10,callback){
        // url
        let url = this.BASE_URL + "/get?page=" + page + "&limit=" + limit;
        // 发送请求
        request.get(url,callback);
    },
    //自动生成编号
    genWorkoderCode(callback){
        let url=this.BASE_URL+'/GenerateAWorkOrder';
        request.get(url,callback);
    },
    //新增工单
    save(proWorkorder,callback){
       let url=this.BASE_URL+'/save';
       request.post(url,proWorkorder,callback);
    },
    //完成工单确认
    updateStatus(workorderCode,callback){
        console.log("sssssss"+workorderCode);
        request.get(this.BASE_URL + "/updateStatus?workorderCode=" + workorderCode,callback);
       
    },
    deleteWorkorder(workorderCode,callback){
        request.delete(this.BASE_URL+"/deleteWorkorder?workorderCode="+workorderCode,callback);
    }
}

// 将dictRequest暴漏出去
export default workorderRequest;